/**
 *	Contains 'Rules' / 'Win conditions' for the 'Connect 4' game type
**/

"use strict"


/**
 *	Add game rules
**/
GameLogic.validator.addRules({
	
	// in connect 4, pieces 'drop down,' so they must always be at the lowest level
	checkPieceAtLowestLevel: function(game, move) {
	
		// must be on the bottom of the board
		if ( move.y === game.board.h-1 ) {
			return { success: true }
		} else if ( game.state[move.y+1][move.x] === 0 ) {
			return {
				success: false,
				message: "piece must be placed on the bottom or on top of another piece"
			}
		}
		
		return true
	}
	
})



/**
 *	Add win conditions
**/
GameLogic.winChecker.addRules({
	
	// invoke a meta-rule to deal with rows of arbitrary numbers (from 'rules/NCL.js')
	checkRowOf4: function(game) {
		return this.metaCheckRowOfX(game, 4)
	},
	
	checkColumnOf4: function(game) {
		return this.metaCheckColumnOfX(game, 4)
	},
	
	checkDiagonalOf4: function(game) {
		return this.metaCheckDiagonalOfX(game, 0, 0, 4)
	},
	
})